package cn.wolfcode.wolf2w.advice;

import cn.wolfcode.wolf2w.exception.LogicException;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommControllerAdvice {
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object hander(Exception e) {
        e.printStackTrace();
//e.getMessage()表示是获取抛的LogicException异常里面的错误信息
//        e.getMessage()表示获取我们自己抛的异常里面的信息
        return new JsonResult(JsonResult.CODE_ERROR_PARAM,e.getMessage(),null);
    }
//除去LogicException异常的其他异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object handlerExt(RuntimeException e) {
        e.printStackTrace();
        //系统异常，请联系管理员
        return JsonResult.defaultError();
    }
}
